//
//  MYXProfitDealViewController.m
//  meiyinxiang
//
//  Created by 陈李飞 on 2017/11/4.
//  Copyright © 2017年 hbjApple. All rights reserved.
//收益明细

#import "MYXProfitDealViewController.h"
#import "MYXMyBoossCell.h"
#import "MYX_Bossshouyi_listModel.h"

static NSString *const MYXMyBoossCellIdentifier = @"MYXMyBoossCell";
@interface MYXProfitDealViewController ()<UITableViewDataSource, UITableViewDelegate, UIGestureRecognizerDelegate,UIActionSheetDelegate,UINavigationControllerDelegate,UIAlertViewDelegate>
@property(nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *dataArr;
@property(nonatomic, assign) int pageStart;
@property(nonatomic, assign) int type;//判断是否刷新
@property(nonatomic, strong) MYXHttpManager *MYXHttpMan;

@end

@implementation MYXProfitDealViewController


-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.MYXHttpMan =[[MYXHttpManager alloc]init];
    self.pageStart=1;
    [self.tableView.mj_header beginRefreshing];
    [self createUI];
}


#pragma mark - UI

- (void)createUI
{
    self.tableView.backgroundColor = [UIColor colorWithRed:0.97f green:0.97f blue:0.97f alpha:1.00f];
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:MYXMyBoossCellIdentifier bundle:nil] forCellReuseIdentifier:MYXMyBoossCellIdentifier];
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, WIDTH, HEIGHT+20) style:UITableViewStyleGrouped];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        WS(weakSelf)
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakSelf loadNewData];
            
        }];
        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [weakSelf loadMorewData];
        }];

    }
    return _tableView;
}
#pragma mark - request

- (void)loadNewData
{
    [self.tableView.mj_header beginRefreshing];
    [self.dataArr removeAllObjects];
    self.pageStart = 1;
    self.type =0;
    [self initUsefrozenmoney:self.pageStart];
    
}
- (void)loadMorewData
{
    if (self.tableView.mj_header.isRefreshing) {
        return;
    }
    self.pageStart ++;
    self.type =1;
    [self initUsefrozenmoney:self.pageStart ];
}

#pragma mark - tableview datasource and delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MYXMyBoossCell *MYXMyBoossCe = (MYXMyBoossCell *)[tableView dequeueReusableCellWithIdentifier:MYXMyBoossCellIdentifier];
    MYXMyBoossCe.selectionStyle = UITableViewCellSelectionStyleNone;
    MYX_Bossshouyi_listModel *MYX_Bossshouyi_listM =self.dataArr[indexPath.row];
    MYXMyBoossCe.MYX_Bossshouyi_listMod =MYX_Bossshouyi_listM;
    return MYXMyBoossCe;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return MYY_wallet_cell_H;
}


-(void)initUsefrozenmoney:(int)page{
    if (self.type==0) {
        [self.dataArr removeAllObjects];
    }
    [self.MYXHttpMan PageIndex:page usefrozenmoneyList:^(NSArray *usefrozenmoneyListArray) {
        if (usefrozenmoneyListArray.count>0) {
            [self.dataArr addObjectsFromArray:usefrozenmoneyListArray];
        }
        
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];

        
    } failure:^(NSString *errorCode) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        [JXTHUDHelper showHUDText:errorCode type:@"error" inView:nil];
    } netDown:^{
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        [JXTHUDHelper showHUDText:@"网络出错了～" type:@"error" inView:nil];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
